/*
 * Vent_Deudas.java
 *
 * Created on 4 de septiembre de 2008, 01:04 PM
 */

package administrador;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTable;
import java.math.*;
import java.util.Calendar;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

/**
 *
 * @author  daniel1
 */
public class Vent_Deudas extends javax.swing.JFrame {
Conexion conexion;
Usuario user;

 //Nath Redondeo
    NumberFormat nf = NumberFormat.getNumberInstance();
   
    /** Creates new form Vent_Deudas */
    public Vent_Deudas(Conexion cEnt,Usuario user) {
        //Configuro Redondeo
        DecimalFormat dec=(DecimalFormat)nf;
        dec.applyPattern("###.##");
        nf.setMaximumFractionDigits(2);
        nf.setRoundingMode(RoundingMode.HALF_UP);
        
        this.conexion=cEnt;
        this.user=user;
        initComponents();
        //setBounds(200,100,746,634);
        //setVisible(true);
        refrescar();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        contenedor = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaDeudores = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaDeudas = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        txt_deudores = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txt_deudas = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(administrador.AdministradorApp.class).getContext().getResourceMap(Vent_Deudas.class);
        contenedor.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("contenedor.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("contenedor.border.titleFont"), resourceMap.getColor("contenedor.border.titleColor"))); // NOI18N
        contenedor.setName("contenedor"); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        tablaDeudores.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Fecha Emision", "Cedula", "Deuda", "Nombre", "Observacion", "Plazo (Meses)", "Valor", "Dias Faltantes!!"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaDeudores.setName("tablaDeudores"); // NOI18N
        jScrollPane2.setViewportView(tablaDeudores);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 570, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
        );

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setLayout(new java.awt.BorderLayout());

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tablaDeudas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Fecha Emision", "RUC", "Deudas", "Nombre", "Observaciones", "Plazo (Meses)", "Valor ", "Dias Faltantes !"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaDeudas.setName("tablaDeudas"); // NOI18N
        jScrollPane1.setViewportView(tablaDeudas);

        jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setName("jButton4"); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setName("jButton5"); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        txt_deudores.setText(resourceMap.getString("txt_deudores.text")); // NOI18N
        txt_deudores.setName("txt_deudores"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        txt_deudas.setText(resourceMap.getString("txt_deudas.text")); // NOI18N
        txt_deudas.setName("txt_deudas"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setActionCommand(resourceMap.getString("jButton1.actionCommand")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout contenedorLayout = new javax.swing.GroupLayout(contenedor);
        contenedor.setLayout(contenedorLayout);
        contenedorLayout.setHorizontalGroup(
            contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(contenedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(contenedorLayout.createSequentialGroup()
                        .addComponent(jButton5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(contenedorLayout.createSequentialGroup()
                                    .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(contenedorLayout.createSequentialGroup()
                                            .addGap(293, 293, 293)
                                            .addComponent(jLabel3))
                                        .addComponent(jLabel2))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
                                    .addComponent(txt_deudores, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(contenedorLayout.createSequentialGroup()
                        .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, contenedorLayout.createSequentialGroup()
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 190, Short.MAX_VALUE)
                                .addComponent(jLabel4)
                                .addGap(27, 27, 27)
                                .addComponent(txt_deudas, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(69, Short.MAX_VALUE))
        );
        contenedorLayout.setVerticalGroup(
            contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, contenedorLayout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(contenedorLayout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txt_deudores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2))
                    .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(contenedorLayout.createSequentialGroup()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(contenedorLayout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addGroup(contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt_deudas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)))
                    .addGroup(contenedorLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(37, 37, 37))
        );

        getContentPane().add(contenedor, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// TODO add your handling code here:
    int fila=tablaDeudores.getSelectedRow();
    if(fila>=0){
    try {
        String cod_cuenta = tablaDeudores.getValueAt(fila, 2).toString();
        String cod_cliente = tablaDeudores.getValueAt(fila, 1).toString();
        Vent_CuentasCobrar vcc=new Vent_CuentasCobrar(conexion,cod_cliente,cod_cuenta,this,user);

    } catch (Exception e) {
        System.err.println(e);
    }
    }else{
    JOptionPane.showMessageDialog(this,"Tiene que seleccionar un Deudor","Informacion",JOptionPane.INFORMATION_MESSAGE);
    }
}//GEN-LAST:event_jButton5ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
  FPagoPagar fp=new FPagoPagar(conexion,user,this);  
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:
    int fila=tablaDeudas.getSelectedRow();
    if(fila>=0){
    try {
        String cod_cuenta = tablaDeudas.getValueAt(fila, 2).toString();
        String cod_cliente = tablaDeudas.getValueAt(fila, 1).toString();
        Vent_CuentasPagar vcc=new Vent_CuentasPagar(conexion,cod_cliente,cod_cuenta,this,user);

    } catch (Exception e) {
        System.err.println(e);
    }
    }else{
    JOptionPane.showMessageDialog(this,"Tiene que seleccionar una Deuda","Informacion",JOptionPane.INFORMATION_MESSAGE);
    }
}//GEN-LAST:event_jButton4ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
    CreaCliente c_c=new CreaCliente(conexion,"",this,user);
}//GEN-LAST:event_jButton1ActionPerformed
    public void refrescar(){
    llenoTablas();
    establescoFormatoTabla();
    }
    
    public void limpio(JTable tablita){
    //Limpio Tabla
        int filas=tablita.getRowCount();
        int cont=0;
        while(cont<filas){
            try{
                for(int i=0;i<5;i++){
                    //System.out.println("valor fila:"+cont+" columnas: "+i);
                    tablita.setValueAt(null,cont,i);
                    // System.out.println(toma);
                }
            }catch(Exception e){};
            cont++;
        }
    }
    
    public void llenoTablas(){
        //Limpio las tablas primero:
        limpio(tablaDeudores);
        limpio(tablaDeudas);
        
        System.out.println("LLega hasta aqui:"+conexion.estado);
        ResultSet resp=conexion.consultarBase("SELECT c.*,l.nombre,l.apellido FROM cuentaspendientes c,cliente l where c.pagado like 'falta' and c.cod_cliente=l.cod_cliente order by fecha desc;");
        
        try {
            resp.beforeFirst();
            while(resp.next()){
            int codCuenta=resp.getInt(1);//codCuenta
            String codCliente=resp.getString(2);//codcliente
            String codFactura=resp.getString(3);//F-Ncodfactura
            String responsable=resp.getString(4);//Responsable
            String fechaEmi=resp.getDate(5).toString();//fecha
            double valor=resp.getDouble(6);//valor
            int plazo=resp.getInt(7);//plazo
            String obs=resp.getString(8);//observaciones
            String estado=resp.getString(9);//pagadp
            String fechaMax=resp.getDate(10).toString();//fechamax
            String tipo=resp.getString(11).toString();//tipo
            String nomCliente=resp.getString(12)+" "+resp.getString(13);
           
                if (!estado.equals("pagado")) {
                    //selecciono Cuentas x Cobrar
                    if (tipo.equals("xcobrar")) {
                        //Lleno tabla de Cuentas x Cobrar:
                        int fila=cuentaFilaOcupadas(tablaDeudores);
                        tablaDeudores.setValueAt(fechaEmi, fila, 0);//Fecha de Emision
                        tablaDeudores.setValueAt(codCliente, fila, 1);//cedulaCliente
                        tablaDeudores.setValueAt(codCuenta, fila, 2);//NumDeuda
                        tablaDeudores.setValueAt(nomCliente, fila, 3);//NombreCliente
                        tablaDeudores.setValueAt(obs, fila, 4);//Observaciones
                        tablaDeudores.setValueAt(plazo, fila, 5);//Plazo
                        tablaDeudores.setValueAt(valor, fila, 6);//Total
                        
                        //Deduzco y pongo los dias faltantes en para que se pase de la fecha maxima.
                        int diasRestantes=sacoDiasRestantes(fechaMax);
                        tablaDeudores.setValueAt(diasRestantes, fila, 7);//Fecha MAX
                        
                        
                        
                        //Actualizo el total:
                        // System.out.println("Entra en actualiza");
                        int numeroCol=tablaDeudores.getRowCount();
                        int cont=0;
                        double acumula=0;
                        String toma;

                        //Muestro Los Subtotales:
                        while (cont<numeroCol){

                            try{
                                toma=tablaDeudores.getValueAt(cont, 6).toString();
                                acumula=acumula+Double.parseDouble(toma);
                            } catch(Exception e){};
                            cont++;
                        }
                        txt_deudores.setText(String.valueOf(nf.format(acumula).replaceAll(",",".")));

                        
                        
                    } else {
                    //Aqui aparecen las Deudas x Pagar:
                        //Lleno tabla de Cuentas x Cobrar:
                        int fila=cuentaFilaOcupadas(tablaDeudas);
                        tablaDeudas.setValueAt(fechaEmi, fila, 0);//Fecha de Emision
                        tablaDeudas.setValueAt(codCliente, fila, 1);//cedulaCliente
                        tablaDeudas.setValueAt(codCuenta, fila, 2);//NumDeuda
                        tablaDeudas.setValueAt(nomCliente, fila, 3);//NombreCliente
                        tablaDeudas.setValueAt(obs, fila, 4);//Observaciones
                        tablaDeudas.setValueAt(plazo, fila, 5);//Plazo
                        tablaDeudas.setValueAt(valor, fila, 6);//Total
                        
                        //Deduzco y pongo los dias faltantes en para que se pase de la fecha maxima.
                        int diasRestantes=sacoDiasRestantes(fechaMax);
                        tablaDeudas.setValueAt(diasRestantes, fila, 7);//Fecha MAX
                        
                        
                        int numeroCol=tablaDeudas.getRowCount();
                        int cont=0;
                        double acumula=0;
                        String toma;

                        //Muestro Los Subtotales:
                        while (cont<numeroCol){

                            try{
                                toma=tablaDeudas.getValueAt(cont, 6).toString();
                                acumula=acumula+Double.parseDouble(toma);
                            } catch(Exception e){};
                            cont++;
                        }
                        txt_deudas.setText(String.valueOf(nf.format(acumula).replaceAll(",",".")));

                        
                    }
                }

            }

        } catch (SQLException ex) {
            Logger.getLogger(Vent_Deudas.class.getName()).log(Level.SEVERE, null, ex);
        }



    }
    
    public int sacoDiasRestantes(String fechaMax){
        //Fecha Maxima
        String[] partesM=fechaMax.split("-");
        //Fecha Actual
        String fechaActual=new java.sql.Date(System.currentTimeMillis()).toString();
        String[] partesA=fechaActual.split("-");
        
        Calendar c1 = Calendar.getInstance(); 	//new GregorianCalendar();
	Calendar c2 = Calendar.getInstance(); 	//new GregorianCalendar();
	//Defino las dos en el calendario:
        c1.set(Integer.parseInt(partesA[0]),Integer.parseInt(partesA[1]),Integer.parseInt(partesA[2])); 
        c2.set(Integer.parseInt(partesM[0]),Integer.parseInt(partesM[1]),Integer.parseInt(partesM[2])); 
	String dias=String.valueOf((c2.getTime().getTime() - c1.getTime().getTime())/(24*3600*1000));
        int diasRes=Integer.parseInt(dias);
	
    return diasRes;
    }
    
    public void establescoFormatoTabla(){
    //Defino los Iconos a Usar la estructura de la tabla:
    org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(administrador.AdministradorApp.class).getContext().getResourceMap(AdminTerminal.class);
    java.net.URL imgURL = getClass().getResource("/administrador/resources/imagenes/" + "atrasado.png");
    ImageIcon icono1=new ImageIcon(imgURL, "todo bien");
    Icon[] iconos={icono1};
   
    //Creo el Render
    RenderTabla miRender = new RenderTabla(iconos);
    //Aplico a la Tabla Deudores:
    tablaDeudores.setDefaultRenderer(Object.class, miRender);
    tablaDeudores.updateUI();
    //Aplico a la Tabla de Deudas:
    tablaDeudas.setDefaultRenderer(Object.class, miRender);
    tablaDeudas.updateUI();

    
    }
    
    
     public int cuentaFilaOcupadas(JTable tabla){
        int totalfilas=tabla.getRowCount();
        int contador=0;
        Object valor;
        for (contador=0;contador<totalfilas;contador++) {
            valor=tabla.getValueAt(contador,0);
            if (valor==null){
                break;
            }
            
        }
        //System.out.println("El numero de fila ocupadas es:"+contador);
        return contador;
    }

    public void llenoDeudas(){
    
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JPanel contenedor;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tablaDeudas;
    private javax.swing.JTable tablaDeudores;
    private javax.swing.JTextField txt_deudas;
    private javax.swing.JTextField txt_deudores;
    // End of variables declaration//GEN-END:variables

}
